﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevExpress.Utils;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.Depo
{
    public partial class GpDurum : XForm
    {
        int CKBatchId;
        public GpDurum(int _CKBatchId)
        {
            InitializeComponent();
            CKBatchId = _CKBatchId;
            this.Text += "- " + AppSession.Lookups.CKBatch.FindByCKBatchId(CKBatchId).Notes;
        }

        private void GpDurum_Load(object sender, EventArgs e)
        {
            
            gridView1.Init("GetGpDurum", CKBatchId);
            gridView1.AddDetailGrid(gridView2, "Model");

            gridView1.AddColumn("CikanAdet", typeof(int), "SUM(Child({FK}).CikanAdet)");
            gridView1.AddColumn("CompletionPct", typeof(decimal), "100 * CikanAdet / Adet");
            gridView1.FormatAsPercentage("CompletionPct");
            gridView2.FormatAsDate("Tarih");

            gridView1.FormatAsNumber(0, "Adet", "CikanAdet");
            gridView2.FormatAsNumber(0, "Adet", "CikanAdet");
            gridView2.MakeColumnInvisible("Model");

            gridView1.AddSummary("Adet", "CikanAdet");
            gridView2.AddSummary("Adet", "CikanAdet");

            gridView2.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView2_RowCellStyle);
            splitContainerControl1.AutoSize();
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            txtInfo.Caption = "Kalan Yüzde: %" + (gridView1.Dataset().Tables[2].Rows[0]["KalanYuzde"]).ToDecimal();
        }

        void gridView2_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
                if (e.Column.FieldName == "CikanAdet")
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }
    }
}
